package com.wolainfo.simulator.model.tfi;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;

@Entity
@IdClass(TransactionBalance.TransactionBalanceId.class)
public class TransactionBalance implements Serializable{
    private static final long serialVersionUID = 4031394283172782161L;
    @Id
    private Integer           fundTransactionId;
    @Id
    private Integer           accountId;
    private BigDecimal        shareBalance;
    private String            fund;
    private String            shareClass;

    public Integer getFundTransactionId(){
        return fundTransactionId;
    }

    public void setFundTransactionId(Integer fundTransactionId){
        this.fundTransactionId = fundTransactionId;
    }

    public Integer getAccountId(){
        return accountId;
    }

    public void setAccountId(Integer accountId){
        this.accountId = accountId;
    }

    public BigDecimal getShareBalance(){
        return shareBalance;
    }

    public void setShareBalance(BigDecimal shareBalance){
        this.shareBalance = shareBalance;
    }

    public String getFund(){
        return fund;
    }

    public void setFund(String fund){
        this.fund = fund;
    }

    public String getShareClass(){
        return shareClass;
    }

    public void setShareClass(String shareClass){
        this.shareClass = shareClass;
    }

    public static class TransactionBalanceId{
        public TransactionBalanceId(){}
        private Integer fundTransactionId;
        private Integer accountId;

        public Integer getFundTransactionId(){
            return fundTransactionId;
        }

        public void setFundTransactionId(Integer fundTransactionId){
            this.fundTransactionId = fundTransactionId;
        }

        public Integer getAccountId(){
            return accountId;
        }

        public void setAccountId(Integer accountId){
            this.accountId = accountId;
        }

        @Override
        public boolean equals(Object obj){
            if(!(obj instanceof TransactionBalanceId))
                return false;
            TransactionBalanceId id = (TransactionBalanceId)obj;
            if(fundTransactionId.compareTo(id.fundTransactionId) != 0)
                return false;
            if(accountId.compareTo(id.accountId) != 0)
                return false;
            return true;
        }

        @Override
        public int hashCode(){
            return fundTransactionId.hashCode() * accountId.hashCode();
        }
    }
}
